
public class Rational implements Comparable
{
		private int numberator;
		private int denominator;
		
		private int UCLN(int a, int b)
		{
			if( a == 0)
				return b;
			else if(b == 0) return a;
			else if(a >= b) return UCLN(a % b, b);
			else return UCLN(b % a, a);
		}
		
		public void Reduce()
		{
			int x = UCLN(numberator, denominator);
			numberator = numberator / x;
			denominator = denominator / x;			
		}
		
		public void Reciprocal()
		{
			int tg = numberator;
			numberator = denominator;
			denominator = tg;
		}
		
		public int BCNN(int a, int b)
		{
			int x = UCLN(a, b);
			return a * b / x;
		}
		
		public int Add(int tSo, int mSo)
		{
			int x = BCNN(denominator, mSo);
			int y = (x / denominator) * numberator + (x / mSo) * tSo;
			return y;
			
		}
		
		public int Subtract(int tSo, int mSo)
		{
			int x = BCNN(denominator, mSo);
			int y = (x / denominator) * numberator - (x / mSo) * tSo;
			return y;			
		}
		
		public int Multiply(int tSo, int mSo)
		{
			int y = tSo * numberator + mSo * denominator;
			return y;
			
		}
		
		public int Divide(int tSo, int mSo)
		{
			int y = tSo * denominator + mSo * numberator;
			return y;
			
		}

		@Override
		public int compareTo(Object o) {
			// TODO Auto-generated method stub
			Rational b = (Rational)o;
			int x = numberator / denominator * 10000;
			int y = b.numberator / b.denominator * 10000;
			if(x == y)
				return 0;
			return -1;
		}
		
		
}
